package com.cloudfast.context.error;

@SuppressWarnings("serial")
public class CloudException extends RuntimeException {
    private int code;
    private String msg;
    private Exception exception;
    private ErrorCode errorCode;

    public CloudException(ErrorCode errorCode) {
        this.msg = errorCode.getMsg();
        this.code = errorCode.getCode();
        this.errorCode = errorCode;
    }

    public CloudException(ErrorCode errorCode, String msg) {
        this.msg = String.format(errorCode.getDefaultMsg(), msg);
        errorCode.setMsg(this.msg);
        this.code = errorCode.getCode();
        this.errorCode = errorCode;
    }

    public CloudException(Exception e) {
        this.exception = e;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Exception getException() {
        return exception;
    }

    public void setException(Exception exception) {
        this.exception = exception;
    }

    public ErrorCode getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(ErrorCode errorCode) {
        this.errorCode = errorCode;
    }
}
